package com.mas.monitor;

import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import java.util.Iterator;
import java.util.Map;

import com.mas.common.AgentUtil;
import com.mas.resource.ResourceAllocator;

public class TickerReleaseResources extends TickerBehaviour {
	
	Map resourcesCatalog;
	
	public TickerReleaseResources(Agent a, long period) {
		super(a, period);
		resourcesCatalog = ((MonitorResourceAgent)myAgent).getMapResourceAllocator();
	}

	protected void onTick() 
    {
		AgentUtil.logInfo(myAgent, "Release all resources");
		for (Iterator value = resourcesCatalog.values().iterator(); value.hasNext();) {
			ResourceAllocator resource = (ResourceAllocator)value.next();
			AgentUtil.debug(myAgent, "TickerReleaseResources: Release " + resource.getResourcePurchased() + " from " + resource.getResourceName());
			resource.releaseResource(resource.getMaxAllocationValue()); //release all
		}

    }
}
